package com.bosssoft.trainee.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bosssoft.trainee.entity.po.Menus;
import com.bosssoft.trainee.entity.po.Route;
import com.bosssoft.trainee.mapper.MenusMapper;
import com.bosssoft.trainee.service.MyMenusService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuqiang
 * @date 2022/7/20 11:25
 */
@Service
public class MyMenusServiceImp extends ServiceImpl<MenusMapper, Menus> implements MyMenusService {

    public List<Menus> getMenus(Integer roleId){
        QueryWrapper<Menus> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id",roleId);
        List<Menus> list = this.list(queryWrapper);
        return list;
    }
    public boolean saveRoutes(Integer roleId,List<Integer> list){
        //为空不做处理
        if(list.isEmpty()){
            return true;
        }else {
            QueryWrapper<Menus> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("role_id",roleId);
            //先移除
            this.remove(queryWrapper);
            for(Integer integer : list){
                Menus menus = new Menus(roleId,integer);
                this.save(menus);
            }
            return true;
        }
    }
}
